package top.kaoshanji.p3ch11b;

import top.kaoshanji.p3ch11a.IdGenerator;

/**
 * 代码清单-p3ch11b-373页a：ThreadLocal类的使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/2/5 17:02
 */
public class ThreadLocalIdGenerator {

    private static final ThreadLocal<IdGenerator> idGenerator = new ThreadLocal<IdGenerator>() {
        @Override
        protected IdGenerator initialValue() {
            return new IdGenerator();
        }
    };

    public static int getNext() {
        return idGenerator.get().getNext();
    }

}
